package com.yuan.Controller.admin;


import com.yuan.Service.DishService;
import com.yuan.dto.DishDTO;
import com.yuan.dto.DishPageQueryDTO;
import com.yuan.entity.Dish;
import com.yuan.result.PageResult;
import com.yuan.result.Result;
import com.yuan.vo.DishVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/dish")
@Slf4j
@RequiredArgsConstructor
@Tag(name = "菜品相关接口")
public class DishController {


    private final DishService dishService;

    @PostMapping
    @Operation(description = "新增菜品")
    public Result save(@RequestBody DishDTO dishDTO) {
        log.info("新增菜品：{}", dishDTO);
        dishService.saveWithFlavor(dishDTO);


        return Result.success();
    }


    //菜品分页查询
    @GetMapping("/page")
    @Operation(description = "菜品分页查询")
    public Result<PageResult> page(DishPageQueryDTO dto) {
        log.info("菜品分页查询：{}", dto);

        PageResult pageResult = dishService.pageSelf(dto);
        return Result.success(pageResult);
    }


    //菜品批量删除
    @DeleteMapping
    @Operation(description = "菜品批量删除")
    public Result delete(@RequestParam List<Long> ids) {
        log.info("菜品批量删除：{}", ids);

        dishService.deleteIds(ids);
        return Result.success();
    }

    //根据id查询菜品
    @GetMapping("/{id}")
    @Operation(description = "根据id查询菜品")
    public Result<DishVO> getById(@PathVariable Long id) {
        log.info("根据id查询菜品：{}", id);
        DishVO dishVO = dishService.getByIdWithFlavor(id);
        return Result.success(dishVO);
    }


    //  修改菜品
    @PutMapping("")
    @Operation(description = "修改菜品")
    public Result update(@RequestBody DishDTO dishDTO) {
        log.info("修改菜品：{}", dishDTO);
        dishService.updateWithFlavor(dishDTO);
        return Result.success();
    }

    //菜品起售停售
    @PostMapping("/status/{status}")
    @Operation(description = "菜品起售停售")
    public Result<String> stareOrStop(@PathVariable Integer status, Long id) {
        dishService.startOrStop(status, id);
        return Result.success();
    }


    //    根据分类id查询菜品
    @GetMapping("list")
    @Operation(description = "根据分类id查询菜品")
    public Result<List<Dish>> list(Long categoryId) {
        List<Dish> list = dishService.listSelf (categoryId);
        return Result.success(list);
    }





}
